import {Image} from "antd"
import {Link,useLocation,Outlet,useNavigate} from "react-router-dom"
import { useEffect } from "react"

function Home() {
  const location = useLocation()
  const navigate = useNavigate()
  //const [title,setTitle] = useState('')
  useEffect(()=>{
    if(!localStorage.getItem('token')){
      navigate('/home/erlogin')
    }
  },[])
  //当路由发生跳转的时候，动态设置网站的标题
  useEffect(()=>{
    document.title = location.pathname;
  },[location.pathname])
  return (
    <div>
      <h1>首页</h1>
      <Image
        style={{ width: 50, height: 50 }}
        src="https://picsum.photos/200/300"
        alt="example"
      />
      <h1>GKing</h1>
      <ul>
        <li>
           <Link to="/home/erlogin">员工登录</Link>
        </li>
        <li>
          <Link to="/home/erregister">员工注册</Link>
        </li>
        <li>
          <Link to="/home/erhome">员工首页</Link>
        </li>

      </ul>
      <Outlet />
    </div>
  )
}

export default Home